package weaver.interfaces.jjy.duss.action;

import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.jjy.duss.hr.HR037;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: ecology-9-demo
 * @description: 促销员兼职
 * @author: Dusongsong
 * @create: 2019-12-09
 */
public class WeaHRcxyjzAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        BaseBean baseBean = new BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用WeaHRcxyjzAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select ygh,xm,jzrq,gw1value,rsfw1value,rszfw1value,ygz1value,ygzz1value,gzhsfw1value,gysmc1value,rzlxvalue,zwmcvalue,zwxlvalue,zwcvalue,yxmcvalue,yxkh from " + tablename + " where requestid='"+requestid+"'");
        baseBean.writeLog("select ygh,xm,jzrq,gw1value,rsfw1value,rszfw1value,ygz1value,ygzz1value,gzhsfw1value,gysmc1value,rzlxvalue,zwmcvalue,zwxlvalue,zwcvalue,yxmcvalue,yxkh from " + tablename + " where requestid='"+requestid+"'");
        rs.next();
        String PERNR = Util.null2String(rs.getString("ygh"));
        String NACHN = Util.null2String(rs.getString("xm"));
        String BEGDA = Util.null2String(rs.getString("jzrq").replaceAll("-", ""));//兼职日期
        String PLANS = Util.null2String(rs.getString("gw1value"));
        String WERKS = Util.null2String(rs.getString("rsfw1value"));
        String BTRTL = Util.null2String(rs.getString("rszfw1value"));
        String PERSG = Util.null2String(rs.getString("ygz1value"));
        String PERSK = Util.null2String(rs.getString("ygzz1value"));
        String ABKRS = Util.null2String(rs.getString("gzhsfw1value"));
        String ZHR_GYS = Util.null2String(rs.getString("gysmc1value"));
        String ZHR_RZLX = Util.null2String(rs.getString("rzlxvalue"));
        String ZHR_ZW = Util.null2String(rs.getString("zwmcvalue"));
        String ZHR_ZWXL = Util.null2String(rs.getString("zwxlvalue"));
        String ZHR_ZWC = Util.null2String(rs.getString("zwcvalue"));
        String BANKL = Util.null2String(rs.getString("yxmcvalue"));//银行代码
        String BANKN = Util.null2String(rs.getString("yxkh"));//银行卡号

        Map<String, String> map = new HashMap();
        map.put("IV_PERNR", PERNR);
        map.put("PERNR", PERNR);
        map.put("MASSN","ZB");
        map.put("MASSG","B1");
        map.put("NACHN", NACHN);
        map.put("BEGDA", BEGDA);
        map.put("PLANS", PLANS);
        map.put("ZHR_ZW",ZHR_ZW);        //职务名称
        map.put("ZHR_ZWXL",ZHR_ZWXL);    //职务序列
        map.put("ZHR_ZWC",ZHR_ZWC);      //职务簇
        map.put("ZHR_PERSG", PERSG);  //员工组
        map.put("ZHR_PERSA", PERSK);  // 员工子组
        map.put("ZHR_RZGW", PLANS);    //任职岗位
        map.put("WERKS", WERKS);
        map.put("BTRTL", BTRTL);
        map.put("PERSG", PERSG);
        map.put("PERSK", PERSK);
        map.put("ABKRS", ABKRS);
        map.put("ZHR_GYS", ZHR_GYS);
        map.put("ZHR_RZLX", ZHR_RZLX);
        map.put("ZHR_RZMD","10000433");
        map.put("BANKN",BANKN);
        map.put("BANKL",BANKL);
        baseBean.writeLog("相关参数:" + map.toString());
        HR037 hr037 = new HR037();
        try{
            Map resultMap = hr037.execute(map);
            String flag = (String)resultMap.get("flag");
            String message = (String)resultMap.get("message");
            baseBean.writeLog("SAP返回结果——flag:" + flag + ";message:" + message);
            if("s".equalsIgnoreCase(flag)){
                return Action.SUCCESS;
            }else {

                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
                return Action.FAILURE_AND_CONTINUE;
            }
        }catch(Exception e){
            e.printStackTrace();
            baseBean.writeLog("异常参考:" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent(e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }


    }
}
